
/* ...
* @author Ludo
* @version 1.1
*/

import clases.MadParser.IndividualStats.MadJugador;
import clases.MadParser.MadParser;
import mx.utils.Delegate;
import flash.external.ExternalInterface;
import mx.controls.DataGrid;
import mx.controls.gridclasses.DataGridColumn;
import mx.styles.CSSStyleDeclaration;

class clases.MadIndividualStats extends MovieClip {

	// Modo local
	public static var local:Boolean = false;

	// Ruta
	public static var pathLocal:String = "xml/Primero.xml";

	// Fichero XML
	private var xmlFile:XML;
	
	// Parseador
	private var madParser:MadParser;

	// Grid
	public var gridTeam1:DataGrid;
	public var gridTeam1Ex:DataGrid;
	public var gridTeam2Ex:DataGrid;
	public var gridTeam2:DataGrid;
	
	// Textos
	
	public var team1:TextField;
	public var team2:TextField;
	
	
	// Textos de cabecera
	private var name: String;
	private var timePlayed:String;
	private var totalPoints:String;
	private var twoTotalPoints:String;
	private var twoPercent:String;
	private var threeTotalPoints:String;
	private var threePercent:String;
	private var freeThrowTotalPoints:String;
	private var freeThrowPercent:String;
	private var offensiveRebounds:String;
	private var defensiveRebounds:String;
	private var totalRebounds:String;
	private var assistances:String;
	private var steels:String;
	private var turnOvers:String;
	private var blocksFavor:String;
	private var blocksAgainst:String;
	private var faultsCommitted:String;
	private var faultsReceived:String;
	private var ranking:String;

	// Marcos
	private var mcMarcoTeam1:MovieClip;
	private var mcMarcoTeam2:MovieClip;
	
	public function MadIndividualStats() 
	{
		
		mcMarcoTeam1 = createEmptyMovieClip("mcMarcoTeam1",this.getNextHighestDepth());
		
		mcMarcoTeam2 = createEmptyMovieClip("mcMarcoTeam2",this.getNextHighestDepth());
		this._visible = false;
		ExternalInterface.addCallback("pasaXMLIndividualStatsAFlash", null, Delegate.create(this,onLoadExternalXML));
		ExternalInterface.addCallback("preparaCarga", null, Delegate.create(this, preparaCarga));
		ExternalInterface.addCallback("errorProducido", null, Delegate.create(this,errorCargaExterna));
		
		preparaLiterales();
		
		if (_level0.Lenguaje == "he")
		{
			gotoAndStop(2);
		}
		
		madParser = new MadParser();
		if(local)
		{
			getLocalXML();
		}
		else
		{
			trace("Hago la llamada a cargaIndividualStats");
			ExternalInterface.call("cargaIndividualStats",50);
		}
		
		Stage.scaleMode = "noScale";
		Stage.align = "TL";
		Stage.addListener(this);
	}
	
	private function onResize()
	{
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.setSize(Stage.width - gridTeam1._x-5, gridTeam1.height,true);
			gridTeam2.setSize(Stage.width - gridTeam2._x - 5, gridTeam2.height, true);
		}
		else
		{
			
			gridTeam1Ex.setSize(100,gridTeam1.height-gridTeam1.hScroller._height,true);
			gridTeam2Ex.setSize(100,gridTeam2.height-gridTeam2.hScroller._height,true);
			
			gridTeam1Ex.move(Stage.width - 100, gridTeam1._y);
			gridTeam2Ex.move(Stage.width - 100,gridTeam2._y);
			
			gridTeam1.setSize(gridTeam1Ex._x-10, gridTeam1.height,true);
			gridTeam2.setSize(gridTeam1Ex._x - 10, gridTeam2.height, true);
			
			gridTeam1Ex.move(Stage.width - 110, gridTeam1._y);
			gridTeam2Ex.move(Stage.width - 110, gridTeam2._y);
			
			gridTeam1Ex.setSize(110,gridTeam1.height-gridTeam1.hScroller._height,true);
			gridTeam2Ex.setSize(110,gridTeam2.height-gridTeam2.hScroller._height,true);
			
			
		}
		
		
		

		if (_level0.Lenguaje != "he")
		{
			var heightOfScroller = gridTeam1.hScroller._height;
			var finalWidth = gridTeam1._x + gridTeam1.vScroller._x;
			
			mcMarcoTeam1.clear();
			mcMarcoTeam1.FNcuadroColorConAncho(1,0,gridTeam1._y,Stage.width-2,gridTeam1._y+gridTeam1._height-heightOfScroller,undefined,0xFFFFFF,0xFFFFFF,0,true,true);
			mcMarcoTeam1.FNcuadroColorConAncho(1,gridTeam1._x,gridTeam1._y,finalWidth,gridTeam1._y+gridTeam1._height,undefined,0xFFFFFF,0xFFFFFF,0);
			mcMarcoTeam2.clear();
			
			var heightOfScroller = gridTeam2.hScroller._height;
			var finalWidth = gridTeam2._x + gridTeam2.vScroller._x;
			
			mcMarcoTeam2.FNcuadroColorConAncho(1,0,gridTeam2._y,Stage.width-2,gridTeam2._y+gridTeam2._height-heightOfScroller,undefined,0xFFFFFF,0xFFFFFF,0,true,true);
			mcMarcoTeam2.FNcuadroColorConAncho(1, gridTeam2._x, gridTeam2._y, finalWidth, gridTeam2._y + gridTeam2._height, undefined, 0xFFFFFF, 0xFFFFFF, 0);
		}
		else
		{
			
			var heightOfScroller = gridTeam1.hScroller._height;
			var finalWidth = gridTeam1.hScroller._width;
			
			mcMarcoTeam1.clear();
			mcMarcoTeam1.FNcuadroColorConAncho(1,0,gridTeam1._y,Stage.width-2,gridTeam1._y+gridTeam1._height-heightOfScroller,undefined,0xFFFFFF,0xFFFFFF,0,true,true);
			mcMarcoTeam1.FNcuadroColorConAncho(1,gridTeam1._x,gridTeam1._y,finalWidth,gridTeam1._y+gridTeam1._height,undefined,0xFFFFFF,0xFFFFFF,0);
			mcMarcoTeam2.clear();
			
			var heightOfScroller = gridTeam2.hScroller._height;
			var finalWidth = gridTeam1.hScroller._width;
			
			mcMarcoTeam2.FNcuadroColorConAncho(1,0,gridTeam2._y,Stage.width-2,gridTeam2._y+gridTeam2._height-heightOfScroller,undefined,0xFFFFFF,0xFFFFFF,0,true,true);
			mcMarcoTeam2.FNcuadroColorConAncho(1, gridTeam2._x, gridTeam2._y, finalWidth, gridTeam2._y + gridTeam2._height, undefined, 0xFFFFFF, 0xFFFFFF, 0);
			
		}
		/*mcMarcoTeam2.FNcuadroColorConAncho(1,0,gridTeam2._y,Stage.width-2,gridTeam2._y+gridTeam2._height+5,undefined,0xFFFFFF,0xFFFFFF,0);
		mcMarcoTeam1.FNcuadroColorConAncho(1,0,gridTeam1._y+20,Stage.width-20,gridTeam1._y+gridTeam1._height-20,undefined,0xFFFFFF,0xFFFFFF,0);*/
		//mcMarcoTeam2.FNcuadroColorConAncho(1,0,gridTeam2._y,Stage.width-2,gridTeam2._y+gridTeam2._height+5,undefined,0xFFFFFF,0xFFFFFF,0);
		//gridTeam2.setSize(Stage.width, gridTeam2.height,true);
//		gridTeam2.columns[0].width = 100;

		
		if (_level0.Lenguaje == "he")
		{
			gridTeam1.hScroll(gridTeam1.maxHPosition );
			gridTeam2.hScroll(gridTeam2.maxHPosition);
			gridTeam1.hScroller.scrollPosition = gridTeam2.maxHPosition;
			gridTeam2.hScroller.scrollPosition = gridTeam2.maxHPosition;
		}

				
	}
	
	private function preparaLiterales()
	{
		
		if (_level0.Lenguaje == undefined)
		{
			_level0.Lenguaje = "en";
		}
		name = _level0.Nombre;
		timePlayed = _level0.Minutos;
		totalPoints = _level0.Pts;
		twoTotalPoints = _level0["2Pt"];
		twoPercent = _level0["2Pt"];
		threeTotalPoints = _level0["3Pt"];
		threePercent = _level0["3Pt"];
		freeThrowTotalPoints = _level0.TL;
		freeThrowPercent = _level0.TL;
		offensiveRebounds = _level0.O;
		defensiveRebounds = _level0.D;
		totalRebounds= _level0.T;
		assistances = _level0.As;
		steels = _level0.Ro;
		turnOvers = _level0.P;
		blocksFavor = _level0.Tapones + " " + _level0.Afavor;
		blocksAgainst = _level0.Tapones + " " + _level0.EnContra;
		faultsCommitted = _level0.Faltas + " " + _level0.Cometidas;
		faultsReceived = _level0.Faltas + " " + _level0.Recibidas;
		ranking = _level0.Val;		
	}
	private function getLocalXML()
	{
		preparaCarga();
		xmlFile = new XML();
		xmlFile.ignoreWhite = true;
		xmlFile.onLoad = Delegate.create(this,onLoadXML);
/*		xmlFile.onLoad = function(ok)
		{
			trace(this);
		}*/
		xmlFile.load(pathLocal);
	}
	
	private function onLoadXML(ok:Boolean)
	{
		if(ok)
		{
			changeIndividualStats(xmlFile.toString());
		}
		else
		{
			
			quitaCarga();
			trace("** ERROR ** Carga de " + pathLocal);
		}
	}
	
	private function onLoadExternalXML(data:String)
	{
		trace("Llego al cambio de individual stats con " + this);
		changeIndividualStats(data);
		
	}	
	
	private function prepareGrids()
	{
				
		gridTeam1Ex.headerHeight = 23;
		gridTeam1.headerHeight = 23;
		gridTeam2Ex.headerHeight = 23;
		gridTeam2.headerHeight = 23;
		gridTeam1Ex.resizableColumns = false;
		gridTeam2Ex.resizableColumns = false;
		gridTeam1.resizableColumns = false;
		gridTeam2.resizableColumns = false;
		
		
		if (_level.Lenguaje != "he")
		{
			gridTeam1.hScrollPolicy = "on";
			gridTeam2.vScrollPolicy = "on";
			gridTeam1.hScrollPolicy = "on";
			gridTeam2.hScrollPolicy = "on";
			gridTeam1Ex.vScrollPolicy = "none";
			gridTeam2Ex.vScrollPolicy = "none";
		}
		else
		{
			gridTeam1.vScrollPolicy = "none";
			gridTeam2.vScrollPolicy = "none";
			gridTeam1.hScrollPolicy = "on";
			gridTeam2.hScrollPolicy = "on";
			gridTeam1Ex.vScrollPolicy = "on";
			gridTeam2Ex.vScrollPolicy = "on";
		}
		
		
		
	
		/*onEnterFrame = function()
		{
			gridTeam1Ex.vPosition =  gridTeam1.vPosition;
			gridTeam2Ex.vPosition =  gridTeam2.vPosition;
		}*/
		

		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("name");
		columna.headerText = name;
		columna.editable = false;
		columna.sortable = true;
		
		columna.sortOnHeaderRelease = true;
		columna.width = 100;
		columna.fontSize = 9;
		
		
		if (_level0.Lenguaje == "he")
		{
			columna.textAlign = "right";
		}
		
		gridTeam1Ex.addColumn(columna);
		gridTeam2Ex.addColumn(columna);

		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("timePlayed");
		columna.headerText = timePlayed;
		columna.editable = false;
		columna.sortOnHeaderRelease = true;
		columna.fontSize = 9;	
		columna.width = 100;
		columna.textAlign = "center";


		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		

		gridTeam1Ex.addColumn(columna);
		gridTeam2Ex.addColumn(columna);
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("name");
		columna.headerText = name;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = true;
		columna.width = 0;
		columna.fontSize = 9;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		

		
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("totalPoints");
		columna.headerText = totalPoints;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;	
		columna.width = 100;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
	
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("twoPercent");
		columna.headerText = twoPercent;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = true;
		columna.fontSize = 9;	
		columna.width = 100;
		columna.textAlign = "center";
		
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("threePercent");
		columna.headerText = threePercent;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = true;
		columna.fontSize = 9;
		columna.width = 100;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("freeThrowPercent");
		columna.headerText = freeThrowPercent;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = true;
		columna.fontSize = 9;	
		columna.width = 100;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}

		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("offensiveRebounds");
		columna.headerText = offensiveRebounds;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("defensiveRebounds");
		columna.headerText = defensiveRebounds;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;	
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("totalRebounds");
		columna.headerText = totalRebounds;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;	
		columna.width = 100;
		columna.textAlign = "center";
	
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("assistances");
		columna.headerText = assistances;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;	
		columna.width = 100;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("steels");
		columna.headerText = steels;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.width = 100;
		columna.fontSize = 9;	
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}

		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("turnOvers");
		columna.headerText = turnOvers;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;			
		columna.width = 100;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("blocksFavor");
		columna.headerText = blocksFavor;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;			
		columna.width = 100;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("blocksAgainst");
		columna.headerText = blocksAgainst;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;			
		columna.width = 100;
		columna.textAlign = "center";
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("faultsCommitted");
		columna.headerText = faultsCommitted;
		columna.editable = false;
		columna.sortable = true;
		columna.fontSize = 9;			
		columna.width = 100;
		columna.textAlign = "center";
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		var columna:DataGridColumn = new DataGridColumn;
		columna = new DataGridColumn("faultsReceived");
		columna.headerText = faultsReceived;
		columna.editable = false;
		columna.sortable = true;
		columna.sortOnHeaderRelease = false;
		columna.fontSize = 9;
		columna.width = 100;
		
		if (_level0.Lenguaje != "he")
		{
			gridTeam1.addColumn(columna);
			gridTeam2.addColumn(columna);
		}
		else
		{
			columna.textAlign = "center";
			gridTeam1.addColumnAt(0,columna)
			gridTeam2.addColumnAt(0,columna);
		}
		
		gridTeam1.addEventListener("headerRelease", Delegate.create(this,onReleaseHeaderGridTeam1));
		gridTeam2.addEventListener("headerRelease", Delegate.create(this,onReleaseHeaderGridTeam2));
		gridTeam1Ex.addEventListener("headerRelease", Delegate.create(this,onReleaseHeaderGridTeam1Ex));
		gridTeam2Ex.addEventListener("headerRelease", Delegate.create(this,onReleaseHeaderGridTeam2Ex));		
		
		gridTeam1.addEventListener("itemRollOver", Delegate.create(this,onRollOverGridTeam1));
		gridTeam2.addEventListener("itemRollOver", Delegate.create(this,onRollOverGridTeam2));
		gridTeam1Ex.addEventListener("itemRollOver", Delegate.create(this,onRollOverGridTeam1Ex));
		gridTeam2Ex.addEventListener("itemRollOver", Delegate.create(this,onRollOverGridTeam2Ex));

		gridTeam1.addEventListener("itemRollOut", Delegate.create(this,onRollOutGridTeam1));
		gridTeam2.addEventListener("itemRollOut", Delegate.create(this,onRollOutGridTeam2));
		gridTeam1Ex.addEventListener("itemRollOut", Delegate.create(this,onRollOutGridTeam1Ex));
		gridTeam2Ex.addEventListener("itemRollOut", Delegate.create(this,onRollOutGridTeam2Ex));

		gridTeam1.addEventListener("scroll", Delegate.create(this,onScrollGridTeam1));
		gridTeam2.addEventListener("scroll", Delegate.create(this,onScrollGridTeam2));
		gridTeam1Ex.addEventListener("scroll", Delegate.create(this,onScrollGridTeam1Ex));
		gridTeam2Ex.addEventListener("scroll", Delegate.create(this,onScrollGridTeam2Ex));

		gridTeam1.addEventListener("load", Delegate.create(this,onResizeGridTeam1));
		gridTeam2.addEventListener("load", Delegate.create(this,onResizeGridTeam2));
		
		mx.controls.DataGrid.prototype.drawHeaderBG = function(Void) {

			with(this)
			{
				var mc : MovieClip = header_mc;
				mc.clear();
				var clr : Number = getStyle("headerColor");
				var o : Object = __viewMetrics;
				var tot : Number = Math.max(totalWidth, displayWidth+3);
				mc.moveTo(o.left,o.top);
				var matrix : Object = { matrixType : "box", x:0, y:0, w:tot, h:__headerHeight+1, r:Math.PI/2 };
				var colors : Array = [0xCCCCCC,0xCCCCCC, clr ];
				var ratios : Array = [0, 60, 255];
				var alphas : Array = [100, 100, 100];
				mc.beginGradientFill("linear", colors, alphas, ratios, matrix);

				mc.lineStyle(0, 0x000000, 0);
				mc.lineTo(tot, o.top);
				mc.lineTo(tot, __headerHeight+1);
				mc.lineStyle(0, 0x000000, 100);
				mc.lineTo(o.left, __headerHeight+1);
				mc.lineStyle(0, 0x000000, 0);
				mc.endFill();	
			}
		};
		
		if (_global.styles.DataGrid == undefined) {
		   _global.styles.DataGrid = new CSSStyleDeclaration();
		}
		/*gridTeam1Ex.border_mc._visible = false;
		gridTeam2Ex.border_mc._visible = false;
		gridTeam1.border_mc._visible = false;
		gridTeam2.border_mc._visible = false;*/

		_global.styles.DataGrid.setStyle("borderStyle", "none");
		_global.styles.DataGrid.setStyle("borderCapColor", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("shadowCapColor", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("shadowColor", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("borderColor", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("hGridLines", false);
		_global.styles.DataGrid.setStyle("vGridLineColor", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("alternatingRowColors", [0x000000, 0x000000]);
		_global.styles.DataGrid.setStyle("headerColor", 0x000000);
		_global.styles.DataGrid.setStyle("color", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("hGridLineColor", 0xFFFFFF);
		
		_global.styles.DataGrid.setStyle("rollOverColor", 0x4B4B4B);
		_global.styles.DataGrid.setStyle("textRollOverColor", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("textSelectedColor", 0xFFFFFF);
		_global.styles.DataGrid.setStyle("selectedColor", 0x4B4B4B);
		_global.styles.DataGrid.setStyle("themeColor", 0x4B4B4B);
		
		/*gridTeam1Ex.setStyle("vGridLines", false);*/
		/*gridTeam1Ex.setStyle("vGridLines", false);*/
		
	}
	
	private function changeIndividualStats(data:String):Boolean
	{
		preparaCarga();
		
		if (!madParser.parseIndividualStats(data) )
		{
			errorParseado();
			return false;
		}
		
		MovieClip(gridTeam1).content_mc.header_mc.sortArrow.removeMovieClip();
		MovieClip(gridTeam2).content_mc.header_mc.sortArrow.removeMovieClip();

		MovieClip(gridTeam1Ex).content_mc.header_mc.sortArrow.removeMovieClip();
		MovieClip(gridTeam2Ex).content_mc.header_mc.sortArrow.removeMovieClip();
		
		// Preparo ya la precarga
		if(!local)
		{
			ExternalInterface.call("cargaIndividualStats",madParser.expires*1000);
		}
		else
		{
			var intervalo = setInterval(this,"changeIndividualStats",60000,xmlFile.toString());
		}
		
		// Preparo el grid;
		var hasToPrepareGrids = false;
		if(gridTeam1.columnCount < 2)
		{
			hasToPrepareGrids = true;
			prepareGrids();
		}
		
		
		var arrayPlayers:Array = new Array();

		var arrayToDraw = madParser.playersTeam1;
		arrayToDraw.push(madParser.team1Info);		
		for(var i=0;i<=madParser.playersTeam1.length-1;i++)
		{MovieClip(gridTeam1).content_mc.header_mc.sortArrow.removeMovieClip();
			var jugador:MadJugador = madParser.playersTeam1[i];
			var datosJugador = jugador.data;
			var objeto:Object = new Object();
			
			for(var j=0;j<=gridTeam1.columnCount-1;j++)
			{
				var column:DataGridColumn = gridTeam1.columns[j];
				if(isNaN(Number(datosJugador[gridTeam1.columnNames[j]])))
				{
					objeto[gridTeam1.columnNames[j]] = datosJugador[gridTeam1.columnNames[j]];
				}
				else
				{
					objeto[gridTeam1.columnNames[j]] = Number(datosJugador[gridTeam1.columnNames[j]]);
				}
				 
			}
			
			arrayPlayers.push(objeto);
		}
		gridTeam1.dataProvider = arrayPlayers;
		gridTeam1Ex.dataProvider = arrayPlayers;
		
		delete arrayPlayers;
		var arrayPlayers:Array = new Array();
		
		var arrayToDraw = madParser.playersTeam2;
		arrayToDraw.push(madParser.team2Info);
		for(var i=0;i<=arrayToDraw.length-1;i++)
		{
			var jugador:MadJugador = madParser.playersTeam2[i];
			var datosJugador = jugador.data;
			var objeto:Object = new Object();
			
			for(var j=0;j<=gridTeam2.columnCount-1;j++)
			{
				var column:DataGridColumn = gridTeam2.columns[j];
				if(isNaN(Number(datosJugador[gridTeam2.columnNames[j]])))
				{
					objeto[gridTeam2.columnNames[j]] = datosJugador[gridTeam2.columnNames[j]];
				}
				else
				{
					objeto[gridTeam2.columnNames[j]] = Number(datosJugador[gridTeam2.columnNames[j]]);
				}
				 
			}
			
			arrayPlayers.push(objeto);
		}		
		gridTeam2.dataProvider = arrayPlayers;
		gridTeam2Ex.dataProvider = arrayPlayers;
		team1.text = madParser.team1;
		team2.text = madParser.team2;
		
		if (hasToPrepareGrids) finalizePrepareGrids();
		
		quitaCarga();
		this._visible = true;
		return true;

	}
	
	private function finalizePrepareGrids()
	{
		gridTeam1Ex.setSize(100,gridTeam1.height-gridTeam1.hScroller._height,true);
		gridTeam2Ex.setSize(100,gridTeam2.height-gridTeam2.hScroller._height,true);

		//onResize();
		//gridTeam1.removeColumnAt(0);
		//gridTeam2.removeColumnAt(0);
	}

	public function onReleaseHeaderGridTeam1(evt)
	{
		if(!gridTeam1.columns[evt.columnIndex].sortOnHeaderRelease)
		{
			trace(gridTeam1.columnNames[evt.columnIndex]);
			if(evt.target.sortDirection == "ASC"){
				evt.target.dataProvider = evt.target.dataProvider.sortOn(gridTeam1.columnNames[evt.columnIndex], Array.NUMERIC)
				gridTeam1Ex.dataProvider = evt.target.dataProvider.sortOn(gridTeam1.columnNames[evt.columnIndex], Array.NUMERIC)
			} else {
				evt.target.dataProvider = evt.target.dataProvider.sortOn(gridTeam1.columnNames[evt.columnIndex], Array.NUMERIC).reverse()
				gridTeam1Ex.dataProvider = evt.target.dataProvider.sortOn(gridTeam1.columnNames[evt.columnIndex], Array.NUMERIC).reverse()
			}
		}
		MovieClip(gridTeam1Ex).content_mc.header_mc.sortArrow.removeMovieClip();
	}
	
	public function onReleaseHeaderGridTeam2(evt)
	{
		if(!gridTeam2.columns[evt.columnIndex].sortOnHeaderRelease)
		{
			trace(gridTeam2.columnNames[evt.columnIndex]);
			if(evt.target.sortDirection == "ASC"){
				evt.target.dataProvider = evt.target.dataProvider.sortOn(gridTeam2.columnNames[evt.columnIndex], Array.NUMERIC)
				gridTeam2Ex.dataProvider = evt.target.dataProvider.sortOn(gridTeam1.columnNames[evt.columnIndex], Array.NUMERIC)
			} else {
				evt.target.dataProvider = evt.target.dataProvider.sortOn(gridTeam2.columnNames[evt.columnIndex], Array.NUMERIC).reverse()
				gridTeam2Ex.dataProvider = evt.target.dataProvider.sortOn(gridTeam1.columnNames[evt.columnIndex], Array.NUMERIC).reverse()
			}
		}
		MovieClip(gridTeam2Ex).content_mc.header_mc.sortArrow.removeMovieClip();
	}

	public function onRollOverGridTeam1(evt)
	{
		gridTeam1Ex.selectRow(evt.index - gridTeam1Ex.__vPosition,false);
	}
	
	public function onRollOverGridTeam2(evt)
	{
		gridTeam2Ex.selectRow(evt.index - gridTeam2Ex.__vPosition,false);
	}

	public function onRollOverGridTeam1Ex(evt)
	{
		gridTeam1.selectRow(evt.index - gridTeam1.__vPosition,false);
	}
	
	public function onRollOverGridTeam2Ex(evt)
	{
		gridTeam2.selectRow(evt.index - gridTeam2.__vPosition,false);
	}
	
	public function onRollOutGridTeam1(evt)
	{
		gridTeam1Ex.selectedIndex = undefined;
	}
	
	public function onRollOutGridTeam2(evt)
	{
		gridTeam2Ex.selectedIndex = undefined;
	}

	public function onRollOutGridTeam1Ex(evt)
	{
		gridTeam1.selectedIndex = undefined;
	}
	
	public function onRollOutGridTeam2Ex(evt)
	{
		gridTeam2.selectedIndex = undefined;
	}
	
	public function onScrollGridTeam1(evt)
	{
		
		gridTeam1Ex.vPosition =  gridTeam1.vPosition;
	}
			
	public function onScrollGridTeam2(evt)
	{
		gridTeam2Ex.vPosition =  gridTeam2.vPosition;
	}

	public function onScrollGridTeam1Ex(evt)
	{
		
		gridTeam1.vPosition =  gridTeam1Ex.vPosition;
	}
			
	public function onScrollGridTeam2Ex(evt)
	{
		gridTeam2.vPosition =  gridTeam2Ex.vPosition;
	}	
	
	public function onReleaseHeaderGridTeam1Ex(evt)
	{
		MovieClip(gridTeam1).content_mc.header_mc.sortArrow.removeMovieClip();
	}
	
	public function onReleaseHeaderGridTeam2Ex(evt)
	{
		MovieClip(gridTeam1).content_mc.header_mc.sortArrow.removeMovieClip();
	}	
	
	public function onResizeGridTeam1(evt)
	{
		onResize();
	}
	
	public function onResizeGridTeam2(evt)
	{
		
	}	
	
	private function preparaCarga()
	{
		_level0.mcLoading._visible = true;
		_level0.mcLoading.gotoAnPlay(1);
	}

	private function quitaCarga()
	{
		_level0.mcLoading._visible = false;
		_level0.mcLoading.gotoAnStop(1);
	}
	
	private function errorCargaExterna()
	{
		ExternalInterface.call("cargaIndividualStats",1000);		
	}
	
	private function errorParseado()
	{
		ExternalInterface.call("cargaIndividualStats",1000);		
	}	
}